<?php

namespace app\manage\controller\notice;
use app\manage\controller\Base;
class Api extends Base
{
    /**
     * 公告列表
     * @return [type] [description]
     */
    public function page_rows(){
        
        $params = $this->request->param();
        
        $perpagenum = isset($params['limit'])?intval($params['limit']):15;
        $perpagenum = $perpagenum>100?100:$perpagenum;
        $page = isset($params['page'])?intval($params['page']):1;
        $page = $page<1?1:$page;

        unset($params['limit']);
        unset($params['page']);
        $where = [];
        if(isset($params['key'])){
            $where= parseWhere($params['key']);
        }

        $data = model('notice')->getPageDatas($where,$page,$perpagenum);
        $data['code'] = 1;
        return json($data);

    }
    /**
     * 单条公告
     * @return [type] [description]
     */
    public function row(){
        $params = $this->request->param();
        $id = isset($params['id'])?$params['id']:0;
        if(!$id){
            $this->error('id错误');
        }

        $data = model('notice')->getOneData($id);
        return json($data);
    }



    /**
     * 获取公告列表
     * @return [type] [description]
     */
    public function rows(){
        $params = $this->request->param();
        $where = $params;
        unset($where['page']);
        $queryStr = $where?'&'.parseQuery($where):'';
        $where = parseWhere($where);

        $query = new \app\common\query\Notice;

        $data = $query->getRows($where,$queryStr,url('notice.show/index'));
        return json($data);
    }

    

}